package io.lkt.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.lkt.common.util.Query;
import io.lkt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.modules.sys.entity.BBrandPromotionSettleInfoEntity;
import io.lkt.modules.sys.service.BBrandPromotionSettleInfoService;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 品牌推广结算信息表
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2019-05-07 18:11:18
 */
@RestController
@RequestMapping("/sys/bbrandpromotionsettleinfo")
public class BBrandPromotionSettleInfoController {
    @Autowired
    private BBrandPromotionSettleInfoService bBrandPromotionSettleInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:bbrandpromotionsettleinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        Query query=new Query(params);
        List<BBrandPromotionSettleInfoEntity> list=bBrandPromotionSettleInfoService.queryList(query);
        int total=bBrandPromotionSettleInfoService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(list, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:bbrandpromotionsettleinfo:info")
    public R info(@PathVariable("id") Integer id){
        BBrandPromotionSettleInfoEntity bBrandPromotionSettleInfo = bBrandPromotionSettleInfoService.getById(id);

        return R.ok().put("bBrandPromotionSettleInfo", bBrandPromotionSettleInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:bbrandpromotionsettleinfo:save")
    public R save(@RequestBody BBrandPromotionSettleInfoEntity bBrandPromotionSettleInfo){
        bBrandPromotionSettleInfo.setCreateTime(new Date());
        bBrandPromotionSettleInfoService.save(bBrandPromotionSettleInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:bbrandpromotionsettleinfo:update")
    public R update(@RequestBody BBrandPromotionSettleInfoEntity bBrandPromotionSettleInfo){
        ValidatorUtils.validateEntity(bBrandPromotionSettleInfo);
        bBrandPromotionSettleInfo.setModifyTime(new Date());
        bBrandPromotionSettleInfoService.updateById(bBrandPromotionSettleInfo);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:bbrandpromotionsettleinfo:delete")
    public R delete(@RequestBody Integer[] ids){
        bBrandPromotionSettleInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
